"""
@-*- coding: utf-8 -*-
@ python：python 3.8
@ 创建人员：ylx
@ 创建时间：2025/3/7 下午3:27
@ 内容：
"""
from pathlib import Path
import yaml


def get_project_dir():
    current_file = Path(__file__).resolve()
    root_dir = current_file.parents[1]
    return str(root_dir)


def read_yaml(key):
    with open(get_project_dir() + "/extract.yaml") as f:
        value = yaml.load(stream=f, Loader=yaml.FullLoader)
        return value[key]


def write_yaml(data):
    with open(get_project_dir() + "/extract.yaml", mode="a", encoding="utf-8") as f:
        yaml.dump(data, stream=f, allow_unicode=True)


def clean_yaml():
    with open(get_project_dir() + "/extract.yaml", mode="w", encoding="utf-8") as f:
        f.truncate()